package cn.wx.auth.util;

import javax.json.JsonObject;

import org.apache.commons.httpclient.HttpClient;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import net.sf.json.JSONObject;

public class AuthUtil {
	public static final String APPID = "wx027e104fd4a61a17";
	public static final String APPSECRET = "e0bfb0387c7407a1f5f5b4ae95793819";
	public static JSONObject doGetJson(String url) {
		JSONObject jsonObject = null;
		CloseableHttpClient httpClient = HttpClientBuilder.create().build();
		HttpGet httpGet = new HttpGet(url);
		try {
			CloseableHttpClient response = (CloseableHttpClient) httpClient.execute(httpGet);
			HttpEntity entity = ((HttpResponse) response).getEntity();
			if(entity != null) {
				String result = EntityUtils.toString(entity,"UTF-8");
				jsonObject = JSONObject.fromObject(result);
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		httpGet.releaseConnection();
		return jsonObject;
	}
}
